package edu.sctu.zcy.month201505.subwaysystem.V4;

import edu.sctu.zcy.month201505.subwaysystem.V2.DeductionsRules;
import edu.sctu.zcy.month201505.subwaysystem.V2.Passenger;
import edu.sctu.zcy.month201505.subwaysystem.V2.SetPassenger;
import edu.sctu.zcy.month201505.subwaysystem.V2.SetStation;

import java.util.HashMap;
import java.util.List;

/**
 * Created by wswk on 2015/6/7.
 */
public class RunTime extends Thread {

   private List<edu.sctu.zcy.month201505.subwaysystem.V2.Passenger> passengerList;
    public RunTime(List<edu.sctu.zcy.month201505.subwaysystem.V2.Passenger> passengerList){

        this.passengerList = passengerList;
    }

    public void run() {


        for (Passenger passenger : passengerList) {
            System.out.println("乘客" + passenger.getName() + "的起点站为：" + passenger.getStartStation());

            HashMap<Integer, String> station = new SetStation1().setStation();

            HashMap<String, Integer> station1 = new SetStation().setStation();




//            for (int i = 1; i <= station.size(); i++) {
//                if(station.get(i).equals(Passenger.getStartStation())){
//                    System.out.println("乘客"+Passenger.getName()+"上车");
//                }
//
//                System.out.println("下一站"+station.get(i+1));
//                try {
//                    Thread.sleep(2000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                if(station.get(i).equals(Passenger.getEndStation())){
//                    System.out.println("乘客"+Passenger.getName()+"下车");
//                }
//            }
//
////            for (int i = 1; i <= station.size(); i++) {
////
////                if(station.get(i).equals(Passenger.getEndStation())){
////                    System.out.println("乘客"+Passenger.getName()+"下车");
////                }
////                try {
////                    Thread.sleep(2000);
////                } catch (InterruptedException e) {
////                    e.printStackTrace();
////                }
////            }
//
//            System.out.println("该乘客乘车时间为：" +
//                    new DeductionsRules().getCountStation(Passenger.getStartStation(),
//                            Passenger.getEndStation()) * 2000 + "秒");


            int a = station1.get(passenger.getStartStation());
            int b = station1.get(passenger.getEndStation());

            if (a > b) {

                for (int i = a - 1; i >= b; i--) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("下一站是：" + station.get(i));
                    if (station.get(i).equals(passenger.getEndStation())) {
                        System.out.println("乘客" + passenger.getName() + "到站");
                    }
                }

            } else {

                for (int i = a + 1; i <= b; i++) {//5  a --11 b
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("下一站是：" + station.get(i));
                    if (station.get(i).equals(passenger.getEndStation())) {
                        System.out.println("乘客" + passenger.getName() + "到站");
                    }
                }
            }

            System.out.println("该乘客乘车时间为：" +
                    new DeductionsRules().getCountStation(passenger.getStartStation(),
                            passenger.getEndStation()) * 2000 + "秒");
        }
    }

//   public RunTime other1(){
//
//      return new RunTime(new SetPassenger().setPassengerInfo().get(1));
//
//   }
//
//    public RunTime other2(){
//
//      return  new RunTime(new SetPassenger().setPassengerInfo().get(2));
//
//    }
}
